package cn.wolfcode.luowowo.controller;

import cn.wolfcode.luowowo.domain.Banner;
import cn.wolfcode.luowowo.domain.Travel;
import cn.wolfcode.luowowo.query.QueryObject;
import cn.wolfcode.luowowo.query.TravelQuery;
import cn.wolfcode.luowowo.service.IBannerService;
import cn.wolfcode.luowowo.service.ITravelService;
import cn.wolfcode.luowowo.util.JsonResult;
import cn.wolfcode.luowowo.util.ParamMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

//首页banner显示
@RestController
@RequestMapping("index")
public class IndexController {

    @Autowired
    private IBannerService bannerService;

    @Autowired
    private ITravelService travelService;

    @GetMapping("/query")
    public Object query(){
        //首页banner游记前五推荐
        //vue.banners = map.banners;
        List<Banner> banners = bannerService.queryBanner(Banner.TYPE_TRAVEL);

        //攻略推荐，推荐一个
        //vue.stBanner = map.stBanner;
        Banner stBanner = bannerService.queryBanner(Banner.TYPE_STRATEGY).get(0);//拿第一个

        //热门游记列表
        //vue.page = map.page;
        TravelQuery qo = new TravelQuery();
        qo.setOrderType(2); //热门排序，默认是-1
        Page<Travel> page = travelService.query(qo);

        return JsonResult.success(new ParamMap()
                .put("banners", banners)
                .put("stBanner", stBanner)
                .put("page", page)
        );
    }
}
